package com.chensf.studydemo.guide.design

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.chensf.studydemo.R
import com.google.android.material.appbar.AppBarLayout
import kotlinx.android.synthetic.main.activity_pull_refresh_demo.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class PullRefreshDemo : AppCompatActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_pull_refresh_demo)
//        appbar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appbar, offset ->
//            Log.e("appbar", "offset=$offset")
//            swipeLayout.isEnabled = offset>=0
//        })

        swipeLayout.setOnRefreshListener {
            lifecycleScope.launch(Dispatchers.Main){
                delay(1500)
                swipeLayout.isRefreshing = false
            }
        }
    }
}